package top.pengdev.esoffice.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author pengdev
 * @description
 * @date 2020-11-25 11:02
 **/
@Configuration
public class ElasticSearchConfig {

    private static final String HTTP = "http";

    @Value("${elasticsearch.host:127.0.0.1}")
    private String host;
    @Value("${elasticsearch.port:9200}")
    private int port;

    @Bean
    public RestHighLevelClient client(){
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost(host, port, HTTP)));
        return client;
    }
}
